<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitepage
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: index.tpl 2011-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
?>
<script type="text/javascript">
  en4.core.runonce.add(function(){

    <?php if( !$this->renderOne ): ?>
			var anchor = $('profile_sitepages').getParent();
			$('profile_sitepage_previous').style.display = '<?php echo ( $this->paginator->getCurrentPageNumber() == 1 ? 'none' : '' ) ?>';
			$('profile_sitepage_next').style.display = '<?php echo ( $this->paginator->count() == $this->paginator->getCurrentPageNumber() ? 'none' : '' ) ?>';

			$('profile_sitepage_previous').removeEvents('click').addEvent('click', function(){
				en4.core.request.send(new Request.HTML({
					url : en4.core.baseUrl + 'widget/index/content_id/' + <?php echo sprintf('%d', $this->identity) ?>,
					data : {
						format : 'html',
						subject : en4.core.subject.guid,
						page : <?php echo sprintf('%d', $this->paginator->getCurrentPageNumber() - 1) ?>
					}
				}), {
					'element' : anchor
				})
			});

			$('profile_sitepage_next').removeEvents('click').addEvent('click', function(){
				en4.core.request.send(new Request.HTML({
					url : en4.core.baseUrl + 'widget/index/content_id/' + <?php echo sprintf('%d', $this->identity) ?>,
					data : {
						format : 'html',
						subject : en4.core.subject.guid,
						page : <?php echo sprintf('%d', $this->paginator->getCurrentPageNumber() + 1) ?>
					}
				}), {
					'element' : anchor
				})
			});
    <?php endif; ?>
  });
</script>
<ul id="profile_sitepages"  class="sitepages_profile_tab">
  <?php foreach ($this->paginator as $item): ?>
    <li>
      <div class='sitepages_profile_tab_photo'>
        <?php echo $this->htmlLink(Engine_Api::_()->sitepage()->getHref($item->page_id, $item->owner_id, $item->getSlug()), $this->itemPhoto($item, 'thumb.normal')) ?>
      </div>
      <div class='sitepages_profile_tab_info'>
        <div class='sitepages_profile_tab_title'>
          <?php echo $this->htmlLink(Engine_Api::_()->sitepage()->getHref($item->page_id, $item->owner_id, $item->getSlug()), $item->getTitle()) ?>
          <div class="fright">
            <?php if ($this->ratngShow): ?>
              <?php if (($item->rating > 0)): ?>

                <?php
                $currentRatingValue = $item->rating;
                $difference = $currentRatingValue - (int) $currentRatingValue;
                if ($difference < .5) {
                  $finalRatingValue = (int) $currentRatingValue;
                } else {
                  $finalRatingValue = (int) $currentRatingValue + .5;
                }
                ?>

                <span title="<?php echo $finalRatingValue . $this->translate(' rating'); ?>">
                  <?php for ($x = 1; $x <= $item->rating; $x++): ?>
                    <span class="rating_star_generic rating_star" ></span>
                  <?php endfor; ?>
                  <?php if ((round($item->rating) - $item->rating) > 0): ?>
                    <span class="rating_star_generic rating_star_half" ></span>
                  <?php endif; ?>
                </span>
              <?php endif; ?>
            <?php endif; ?>

            <?php if ($item->closed): ?>
              <span>
                <?php echo $this->htmlImage('application/modules/Sitepage/externals/images/close.png', '', array('class' => 'icon', 'title' => $this->translate('Closed'))) ?>
              </span>
            <?php endif; ?>
            <span>
              <?php if ($item->sponsored == 1): ?>
                <?php echo $this->htmlImage('application/modules/Sitepage/externals/images/sponsored.png', '', array('class' => 'icon', 'title' => $this->translate('Sponsored'))) ?>
              <?php endif; ?>
            </span>
            <span>
              <?php if ($item->featured == 1): ?>
                <?php echo $this->htmlImage('application/modules/Sitepage/externals/images/sitepage_goldmedal1.gif', '', array('class' => 'icon', 'title' => $this->translate('Featured'))) ?>
              <?php endif; ?>
            </span>
          </div>
          <div class="clear"></div>
        </div>
        <div class='sitepages_browse_info_date'>
          <?php echo $this->timestamp(strtotime($item->creation_date)) ?> - <?php echo $this->translate('posted by'); ?>
          <?php echo $this->htmlLink($item->getOwner()->getHref(), $item->getOwner()->getTitle()) ?>,
          <?php echo $this->translate(array('%s comment', '%s comments', $item->comment_count), $this->locale()->toNumber($item->comment_count)) ?>,

					<?php $sitepagereviewEnabled = Engine_Api::_()->getDbtable('modules', 'core')->isModuleEnabled('sitepagereview'); ?>
					<?php if ($sitepagereviewEnabled): ?>
						<?php echo $this->translate(array('%s review', '%s reviews', $item->review_count), $this->locale()->toNumber($item->review_count)) ?>,
					<?php endif; ?>

          <?php echo $this->translate(array('%s view', '%s views', $item->view_count), $this->locale()->toNumber($item->view_count)) ?>,
          <?php echo $this->translate(array('%s like', '%s likes', $item->like_count), $this->locale()->toNumber($item->like_count)) ?>
        </div>
        <div class='sitepages_browse_info_blurb'>
          <?php
          // Not mbstring compat
          echo substr(strip_tags($item->body), 0, 350);
          if (strlen($item->body) > 349)
            echo $this->translate("...");
          ?>
        </div>
      </div>
    </li>
  <?php endforeach; ?>
</ul>
<div>
  <div id="profile_sitepage_previous" class="paginator_previous">
    <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Previous'), array(
      'onclick' => '',
      'class' => 'buttonlink icon_previous'
    )); ?>
  </div>
  <div id="profile_sitepage_next" class="paginator_next">
    <?php echo $this->htmlLink('javascript:void(0);', $this->translate('Next'), array(
      'onclick' => '',
      'class' => 'buttonlink_right icon_next'
    )); ?>
  </div>
</div>